﻿using System;
using System.Collections.Generic;
using System.Text;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.DataSourcesGDB;

namespace CanSWAT.ArcSWAT
{
    class PersonalDatabase : SWAT.SWATFile
    {
        public PersonalDatabase(string file) : base(file)
        {
        }

        private IFeatureWorkspace _workspace = null;

        protected IFeatureWorkspace Workspace
        {
            get
            {
                if (_workspace == null)
                {
                    IWorkspaceFactory wf = new AccessWorkspaceFactoryClass();
                    _workspace = wf.OpenFromFile(File, 0) as IFeatureWorkspace;
                }
                return _workspace;
            }
        }

        protected ITable openTable(string tableName)
        {
            IWorkspace2 wp2 = Workspace as IWorkspace2;
            if (!wp2.get_NameExists(esriDatasetType.esriDTTable, tableName))
            {
                throw new System.Exception("Can't find " + tableName + " in " + File + 
                    "This is not an ArcSWAT project.");
            }
            return Workspace.OpenTable(tableName);
        }
    }
}
